<!DOCTYPE html>
<html>
	<!--
		作者：offline
		时间：2018-06-27
		描述：试用期管理
	-->

	<head>
		<!-- 引入框架文件 -->
		<link rel="stylesheet" href="../../model/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<script type="text/javascript" src="../../model/jquery-2.1.0.js"></script>
		<script type="text/javascript" src="../../model/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<link rel="stylesheet" href="../../static/css/ehr.css" />
		<link rel="stylesheet" href="../../static/css/employee.css" />
		<script type="text/javascript" src="../../model/models.js"></script>
		<script type="text/javascript" src="../../model/dispose.js"></script>
		<style type="text/css">
			.show td {
				text-align: center;
			}
			
			.show th {
				text-align: center;
			}
		</style>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<div include="../../static/header.htm"></div>
		<div style="height: 100%;float: left;" include="../../static/aside.htm"></div>

		<div class="aside2">
			<div include="../../static/empManage.htm"></div>
		</div>

		<div class="section">
			<div style="color: white;font-size: 36px;text-align: center; width: 100%; height: 70px;" class="head"><b>员工离职管理</b></div>
			<div class="content">
				<!-- 试用期管理 -->
				<div class="amend">
					<form id="findEmp">
						<div>
							<input id="key" name="key" type="text" placeholder="试用期员工姓名/编号" class="form-control" style="width: 200px; float: left;" />
							<input style="margin: 2px 5px; width: 100px;" type="submit" value="查询" class="btn btn-danger" />
							<!--<input type="hidden" name="page" value="1" />-->
						</div>
					</form>
					<form id="updateDim">
						<div>
							<div class="input-group">
								<span style="float: none;" class="input-group-addon" id="basic-addon1">员工姓名：</span>
								<input id="empName" readonly="readonly" style="width: 200px;" type="text" class="form-control" aria-describedby="basic-addon1">
								<input type="hidden" name="dimEmp.id" id="empId" />
							</div>
							<div class="input-group">
								<span style="float: none;" class="input-group-addon" id="basic-addon1">员工编号：</span>
								<select onchange="showMsg(this)" id="dimEmp" class="form-control" style="width: 200px;">
									<option>员工编号</option>
								</select>
							</div>
						</div>

						<div>
							<select id="status" name="misType" class="form-control" style="width: 200px;">
								<option value="主动辞职">主动辞职</option>
								<option value="辞退">辞退</option>
								<option value="退休">退休</option>
								<option value="开除">开除</option>
								<option value="试用期未通过">试用期未通过</option>
							</select>
						</div>

						<div>
							<input style="width: 295px; margin-top: 20px;" type="submit" class="btn btn-danger" value="确认离职" />
						</div>
					</form>
				</div>
				<!-- 信息查询 -->
				<div class="query">
					<div>
						<form id="findByDate">
							<!-- 已转正员工信息查询 -->
							<h3>离职员工信息查询</h3>
							<!-- 搜索输入框 -->
							<span style="margin-top: 7px;">开始时间：</span>
							<input id="beginDate" name="beginDate" value="2016-06-07" type="date" class="form-control" style="width: 150px;margin-right: 10px;" />
							<span style="margin-top: 7px;">结束时间：</span>
							<input id="endDate" name="endDate" value="2018-09-03" type="date" class="form-control" style="width: 150px;margin-right: 10px;" />
							<input class="btn btn-primary" type="submit" value="查询" style="width: 100px;margin-top: 5px; margin-left: 100px;" />
							<input type="hidden" value="1" id="page" name="page" />
						</form>

					</div>
				</div>

				<div class="show">
					<table class="table table-striped">
						<thead>
							<tr>
								<th>员工编号</th>
								<th>姓名</th>
								<th>性别</th>
								<th>部门名称</th>
								<th>岗位名称</th>
								<th>联系电话</th>
								<th>电子邮件</th>
								<th>所学专业</th>
								<th>离职时间</th>
								<th>离职类型</th>
								<th>离职原因</th>
							</tr>
						</thead>

						<tbody id="searchUserList">
							<tr>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
						</tbody>

					</table>

					<!-- 分页开始 -->
					<nav id="page" style="position: absolute; bottom: 20px;" aria-label="Page navigation">
						<ul id="pagination" class="pagination">
							<li>
								<a href="#" aria-label="Previous">
									<span aria-hidden="true">&laquo;</span>
								</a>
							</li>
							<li>
								<a href="#" aria-label="Next">
									<span aria-hidden="true">&raquo;</span>
								</a>
							</li>
						</ul>
					</nav>

					<!-- 分页结束 -->

				</div>
			</div>
		</div>
	</body>

</html>

<script type="text/javascript">
	// 根据key查询封装
	var flag = true;
	//挂载事件，当表单提交时进行处理
	$("#findEmp").submit(function(e) {

		//阻止表单默认事件，不让表单跳转到其他页面
		e.preventDefault();

		//jq的回调函数中的this，一般表示该事件源，即触发事件的元素
		var $self = $(this);
		//$self.serialize();将表单中的数据进行序列化
		//async:true 采用异步操作
		$.ajax({
			type: "post",
			url: "http://localhost:9090/findEmpByKey",
			"data": $self.serialize(),
			"success": function(obj) {
				if(obj.code == 1) {

					var list = obj.data;
					if(list == null) {
						window.wxc.xcConfirm("查无此人！", "error");
						return;
					}
					if(flag)
						$("#dimEmp").html("");

					if(null == list.length) {
						$("#empId").val(list.id);
						$("#empName").val(list.empName);
						if(flag)
							$("#dimEmp").append("<option value='" + list.id + "'>" + list.id + "</option>");
					} else {
						for(var i = 0; i < list.length; i++) {
							$("#empName").val(list[i].empName);
							$("#empId").val(list.id);
							if(flag)
								$("#dimEmp").append("<option value='" + list[i].id + "'>" + list[i].id + "</option>");
						}
					}
					flag = true;
				} else {
					window.wxc.xcConfirm("查无此人！", "error");
				}
			},
			"dataType": "json",
			async: true
		});
	})
	// 更新按钮提交
	$("#updateDim").submit(function(e) {

		e.preventDefault();
		// 获取proId的值
		var proId = $("#proId").val();
		// 获取status的值
		var status = $("#status").val();

		var $self = $(this);

		$.ajax({
			type: "post",
			url: "http://localhost:9090/addDimission",
			"data": $self.serialize(),
			"success": function(obj) {
				if(obj.data) {
					window.wxc.xcConfirm("离职处理成功！", "success");
				} else {
					window.wxc.xcConfirm("更新失败！", "error");
				}
			},
			"dataType": "json",
			async: true
		});
	});

	// 员工id下拉框 
	function showMsg(obj) {
		var opt = obj.options[obj.selectedIndex];
		//		alert("The option you select is:" + opt.text + "(" + opt.value + ")");
		//		findByKey(opt.value, false, "正常", 1);
		$("#key").val(opt.value);
		flag = false;
		$("#findEmp").submit();
	}

	$("#findByDate").submit(function(e) {
		e.preventDefault();

		var $self = $(this);

		$.ajax({
			type: "post",
			url: "http://localhost:9090/findDimByDate",
			"data": $self.serialize(),
			"success": function(obj) {
				//debugger;断点
				if(null != obj.data) {
					//alert(obj.msg);
					// 显示分页数据
					page = obj.page;
					upPage("pagination", obj.page);

					var list = obj.data;

					var $tbody = $("#searchUserList");
					$tbody.html("");

					for(var i = 0; i < list.length; i++) {
						var $tr = $("<tr></tr>");

						var user = list[i];
						// 员工信息显示

						for(var index in user) {
							if("dimEmp" == index) {
								var h = 0;
								var emp = user[index];
								for(var j in emp) {
									if(h > 7)
										break;
									if("empDiv" == j && emp[j] != null) {
										var $td = $("<td>" + emp[j].depaName + "</td>");
									} else if("empPost" == j && emp[j] != null) {
										var $td = $("<td>" + emp[j].postName + "</td>");
									} else {
										var $td = $("<td>" + emp[j] + "</td>");
									}

									$("#" + j).val(emp[j]);

									$tr.append($td);

									h++;
								}
							}
						}
						
						$tr.append("<td>"+list[i].misDate+"</td>")
						$tr.append("<td>"+list[i].misType+"</td>")
						$tr.append("<td>"+list[i].note+"</td>")
						
						$tbody.append($tr);
					}
				} else {
					window.wxc.xcConfirm("查询无结果！", "error");
				}
			},
			"dataType": "json",
			async: true
		});
	});
</script>